<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Inv_cost extends CI_Controller {

	public function __construct(){
		parent::__construct();
		$this->load->model('wus');
		$this->load->model($this->session->userdata('formodel'));
		$this->load->library('variable');
	}
	public function index(){
		  $this->load->view('layouts/header',$this->variable->load_data($this->session->userdata('title')));
		  	$this->load->view($this->session->userdata('formain'),array(
							'items' => $this->inv_cost_model->get_inv_items() 
					));
		  $this->load->view('layouts/footer');
		 }

 	public function search_cost(){
 		$item_num 		= $this->input->post('item_number');
		$effect_date 	= $this->input->post('effective_date');
		$current 		= ($this->input->post('cur_box') == "ok" ? 'Y' : 'N');
		$future 		= ($this->input->post('fut_box') == "ok" ? 'Y' : 'N');
		$query = $this->inv_cost_model->search_cost_DB($item_num, $effect_date,$current,$future);

		if(!empty($query)) {
			echo json_encode($query);
		}else{
			echo json_encode("none");
		}
 	}
 	public function insert_cost(){
 		$data = array(
 			':p_item_num' 			=> $this->input->post('item_numbers'),
 			':p_bu_id'				=> $this->session->userdata('bu_id'),
 			':p_effective_date'		=> $this->input->post('effective_date'),
 			':p_full_cost'			=> $this->input->post('cost'),
 			':p_user_id'			=> $this->session->userdata('user_id')
 			);
 		$this->inv_cost_model->insert_cost($data);
 	}
 	public function update_cost(){
 		$cost_id = $this->input->post('cost_id');
 		$data = array(
 			':p_trx_type'		=> 'U',
 			':p_item_num'		=> $this->input->post('i_num'),
 			':p_bu_id'			=> $this->session->userdata('bu_id'),
 			':p_effective_date'	=> $this->input->post('edit_effective_date'),
 			':p_full_cost'		=> $this->input->post('edit_cost'),
 			':p_user_id'		=> $this->session->userdata('user_id'),
 			':p_cost_id'		=> $this->input->post('cost_id')
 			);
 		$this->inv_cost_model->update_cost($data);
 	}



 	public function edit_form($id){
	 		$this->load->view($this->session->userdata('foredit'),array(
				'items' => $this->inv_cost_model->get_cost_data($id) 
			));
 	}
 	public function add_form(){
			$this->load->view($this->session->userdata('foradd'),array(
							'items' => $this->inv_cost_model->get_inv_items() 
					));
	}	
	public function view_form($id){
			$this->load->view($this->session->userdata('forview'),array(
					'items' => $this->inv_cost_model->get_cost_data($id)
				));
	}
	 
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */